package control;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import org.apache.log4j.Logger;

import core.Dictionary;
import db.DbDictionaries;

public class SearchWord extends BaseControl{
	/**
	 * this function will perform when submit Translate button on LookUpWord Screen.
	 * 
	 * @param request
	 * @param response
	 * @return return the form that include meaning contain in txtMeaning
	 * @throws PortletException
	 * @throws IOException
	 */
	Logger LOG = Logger.getLogger("SearchWord");
	public form.SearchWord procTranslate(ActionRequest request, ActionResponse response) throws PortletException, IOException {
		int slFromId = Integer.valueOf(request.getParameter("slFrom"));
		
		int slToId = Integer.valueOf(request.getParameter("slTo"));
		
		String txtWord = request.getParameter("txtWord");
		DbDictionaries dictList = new DbDictionaries();
		Dictionary dict = dictList.getDictionary(slFromId, slToId);
		String meaning = dict.lookupWord(txtWord);
		form.SearchWord result = new form.SearchWord();
		result.setTxtmeaning(meaning);
		LOG.info("meaning "+meaning);
		result.setTxtWord(txtWord);
		
		return result;
	}
//	public static void main ( String []args){
//		DbDictionaries dictList = new DbDictionaries();
//		Dictionary dict = dictList.getDictionary(1, 2);
//		String meaning = dict.lookupWord("tech");
//		System.out.println(meaning);
//	}
	public form.LoginForm procLogin(ActionRequest request, ActionResponse response) throws PortletException, IOException {
		return null;
	}
	public form.Contribute procContribute(ActionRequest request, ActionResponse response) throws PortletException, IOException {
		return null;
	}
}
